package com.ss.android.article.browser.main;

import android.content.Intent;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.os.Parcelable;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.ViewTreeObserver;
import android.view.Window;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.VideoView;

import com.bytedance.common.utility.UIUtils;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.ss.android.article.base.feature.model.CategoryItem;
import com.ss.android.article.base.feature.video.IVideoController;
import com.ss.android.article.base.ui.BrowserProgressBar;
import com.ss.android.article.browser.BrowserPage;
import com.ss.android.article.browser.FeedFragment;
import com.ss.android.article.browser.c.SpecialPageHelper;
import com.ss.android.article.browser.constant.CategoryNaviItem;
import com.ss.android.article.browser.constant.Constants;
import com.ss.android.article.browser.constant.NaviItem;
import com.ss.android.article.browser.main.bean.WeatherBean;
import com.ss.android.article.browser.preference.PreferenceManager;
import com.ss.android.article.browser.view.Browser;
import com.ss.android.article.browser.website.NavigationBean;
import com.ss.android.article.browser.website.WebsiteBean;
import com.ss.android.browser.base.wrapper.a.BrowserSharedPreferencesWrapper;
import com.ss.android.browser.base.wrapper.net.BaseNetBean;
import com.ss.android.browser.base.wrapper.net.NavigationCallback;
import com.ss.android.common.util.ImmersedStatusBarHelper;
import com.ss.android.g.a;
import com.ss.android.image.AsyncImageView;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

public final class HomePageFragment extends BaseHomePageFragment implements
        FeedFragment,
        com.ss.android.article.browser.main.BrowserBehavior.a,
        com.ss.android.article.browser.main.BrowserBehavior.BrowserBehavior$b,
        com.ss.android.article.browser.main.ba.a {
    private static final int SDK_INT = Build.VERSION.SDK_INT;
    private static final FrameLayout.LayoutParams LAYOUT_PARAMS = new FrameLayout.LayoutParams(-1, -1);
    ba a;
    private ViewGroup mWebViewContainer;
    private int mRequestedOrientation;
    private String C;
    private ValueCallback mValueCallback;
    private View E;
    private WebChromeClient.CustomViewCallback mCustomViewCallback;
    private FrameLayout G;
    private VideoView mVideoView;
    private BrowserProgressBar mBrowserProgressBar;
    private PreferenceManager mPreferenceManager;
    private TabInspector mTabInspector;
    private LinearLayout mLLSearchRoot;
    private View M;
    private LinearLayout mCategoryNaviGrid;
    private View.OnClickListener QuickCategoryClickListener = new View.OnClickListener() {

        public final void onClick(View view) {
            Object tag = view.getTag();
            if ((tag instanceof CategoryNaviItem)) {
                if (HomePageFragment.this.mMotionDirectionFrameLayout != null) {
                    HomePageFragment.this.mMotionDirectionFrameLayout.a();
                }
                final String categoryName = ((CategoryNaviItem) tag).mCategoryName;
                new Handler().postDelayed(new Runnable() {

                    public final void run() {
                        CategoryItem categoryItem = HomePageFragment.this.mCategoryManager.getCategoryItem(categoryName);
                        if (((BaseHomePageFragment) HomePageFragment.this).mViewPager != null && categoryItem != null) {
                            int v0_1 = ((BaseHomePageFragment) HomePageFragment.this).mCategoryItemList.indexOf(categoryItem);
                            if (v0_1 < 0) {
                                v0_1 = 0;
                            }
                            ((BaseHomePageFragment) HomePageFragment.this).mViewPager.setCurrentItem(v0_1, false);
                        }
                    }
                }, 300);
                new a.a$a("click_quick_category").a("category_name", categoryName).a().a();
            }
        }
    };
    private LinearLayout mWebsiteNavigationGrid;
    private TextView mBrowserPageFakeInputTv;
    private ImageView mBrowserPageRefreshIv;
    private LinearLayout mBrowserPageHeader;
    private String T;
    private View.OnClickListener mRefreshOnClickListener = new View.OnClickListener() {

        public final void onClick(View arg2) {
            if (mBrowser != null) {
                if (mBrowser.isPageLoading()) {
                    mBrowser.c();
                } else {
                    mBrowser.reload();
                }
            }
        }
    };
    private TextView V;
    private TextView W;
    private TextView X;
    private TextView Y;
    private TextView Z;
    private boolean aa;
    private Browser mBrowser;

    public HomePageFragment() {
    }

    public static HomePageFragment newHomePageFragment(Bundle bundle) {
        HomePageFragment homePageFragment = new HomePageFragment();
        homePageFragment.setArguments(bundle);
        return homePageFragment;
    }

    private boolean D() {
        boolean v0 = this.mFeedAreaContainer == null || Math.abs(((BaseHomePageFragment) this).w) <= 0 ? false : true;
        return v0;
    }

    private BrowserPage E() {
        if (this.mTabInspector == null) {
            this.mTabInspector = TabInspector.getInstance();
        }
        BrowserPage v0 = this.mTabInspector != null ? this.mTabInspector.mBrowserPage : null;
        return v0;
    }

    public final void bindWebsiteNavigationGrid(final List<NavigationBean> navigationBeanList) {
        if (navigationBeanList != null && this.mWebsiteNavigationGrid != null) {
            for (int i = 0; i < this.mWebsiteNavigationGrid.getChildCount(); ++i) {
                if (i < 5) {
                    TextView tv_screen_name = this.mWebsiteNavigationGrid.getChildAt(i).findViewById(com.ss.android.article.browser.R.id.tv_screen_name);
                    if (!TextUtils.isDigitsOnly(navigationBeanList.get(i).screen_name)
                            || navigationBeanList.get(i).screen_name.length() <= 8) {
                        tv_screen_name.setText(navigationBeanList.get(i).screen_name);
                    } else {
                        tv_screen_name.setText(Integer.parseInt(navigationBeanList.get(i).screen_name));
                    }

                    if (navigationBeanList.get(i).icon_url.startsWith("http")) {
                        ((AsyncImageView) this.mWebsiteNavigationGrid.getChildAt(i).findViewById(com.ss.android.article.browser.R.id.screen_icon)).setUrl(navigationBeanList.get(i).icon_url);
                    } else {
                        ((ImageView) this.mWebsiteNavigationGrid.getChildAt(i).findViewById(com.ss.android.article.browser.R.id.screen_icon)).setImageResource(Integer.parseInt(navigationBeanList.get(i).icon_url));
                    }
                }
                final int finalI = i;
                this.mWebsiteNavigationGrid.getChildAt(i).setOnClickListener(new View.OnClickListener() {


                    public final void onClick(View arg4) {
                        String v0;
                        if (finalI == 5) {
                            ((ArticleMainActivity) HomePageFragment.this.getActivity()).showWebsiteNavigation();
                            v0 = "更多";
                        } else {
                            v0 = ((NavigationBean) navigationBeanList.get(finalI)).open_url;
                            HomePageFragment.this.n();
                            mBrowser.loadUrl(v0);
                            v0 = ((NavigationBean) navigationBeanList.get(finalI)).screen_name;
                        }
                        new com.ss.android.g.a.a$a("click_guide").a("guide_name", v0).a().a();
                    }
                });
            }
        }
    }

    private void a(boolean arg5, boolean arg6) {
        int v3 = 1024;
        Window window = this.getActivity().getWindow();
        View decorView = window.getDecorView();
        if (arg5) {
            if (arg6) {
                decorView.setSystemUiVisibility(5894);
            } else {
                decorView.setSystemUiVisibility(0);
            }
            window.setFlags(v3, v3);
        } else {
            window.clearFlags(v3);
            decorView.setSystemUiVisibility(0);
        }
    }

    public final void a(float arg3) {
        if (this.a != null) {
            this.a.a(arg3);
        }

        BrowserPage v0 = this.E();
        if (v0 != null) {
            v0.onPageChangedStart(false);
        }

        if (this.x()) {
            ((ArticleMainActivity) this.getActivity()).showRedPoint();
        }
    }

    public final void onProgressChanged(int newProgress) {
        if (this.a != null) {
            this.a.mLLSearchBox.hasFocus();
        }

        if (this.mBrowserProgressBar != null) {
            this.mBrowserProgressBar.setProgress(newProgress);
        }
    }

    public final void onCreateWindow(Message message) {
        if (message != null) {
            WebView v1 = this.mBrowser.getWebView();
            if (v1 != null) {
                ((WebView.WebViewTransport) message.obj).setWebView(v1);
                message.sendToTarget();
            }
        }
    }

    public final void onShowCustomView(View view, WebChromeClient.CustomViewCallback customViewCallback) {
        int requestedOrientation = this.getActivity().getRequestedOrientation();
        this.mRequestedOrientation = requestedOrientation;
        this.onShowCustomView(view, customViewCallback, requestedOrientation);
    }

    public final void onShowCustomView(View view, WebChromeClient.CustomViewCallback customViewCallback, int requestedOrientation) {
        Browser v2 = this.mBrowser;
        if (view != null && this.E == null) {
            try {
                view.setKeepScreenOn(true);
            } catch (SecurityException v0) {
                Log.e(HomePageFragment.TAG, "WebView is not allowed to keep the screen on");
            }

            this.mRequestedOrientation = this.getActivity().getRequestedOrientation();
            this.mCustomViewCallback = customViewCallback;
            this.E = view;
            this.getActivity().setRequestedOrientation(requestedOrientation);
            View decorView = this.getActivity().getWindow().getDecorView();
            this.G = new FrameLayout(this.getContext());
            this.G.setBackgroundColor(ContextCompat.getColor(this.getContext(), 17170444));
            if (view instanceof FrameLayout) {
                if ((((FrameLayout) view).getFocusedChild() instanceof VideoView)) {
                    this.mVideoView = (VideoView) ((FrameLayout) view).getFocusedChild();
                    this.mVideoView.setOnErrorListener(new HomePageFragment.w$a(this, (byte) 0));
                    this.mVideoView.setOnCompletionListener(new HomePageFragment.w$a(this, (byte) 0));
                }
            } else if (view instanceof VideoView) {
                this.mVideoView = ((VideoView) view);
                this.mVideoView.setOnErrorListener(new HomePageFragment.w$a(this, (byte) 0));
                this.mVideoView.setOnCompletionListener(new HomePageFragment.w$a(this, (byte) 0));
            }

            ((FrameLayout) decorView).addView(this.G, HomePageFragment.LAYOUT_PARAMS);
            this.G.addView(this.E, HomePageFragment.LAYOUT_PARAMS);
            decorView.requestLayout();
            this.a(true, true);
            if (v2 == null) {
                return;
            }

            v2.setWebViewVisibility(4);
            return;
        }

        if (customViewCallback != null) {
            try {
                customViewCallback.onCustomViewHidden();
            } catch (Exception v0_2) {
                Log.e(HomePageFragment.TAG, "Error hiding custom view", ((Throwable) v0_2));
            }
        }
    }

    public final void onShowFileChooser(ValueCallback valueCallback) {
        File v3;
        Object v1 = null;
        if (this.mValueCallback != null) {
            this.mValueCallback.onReceiveValue(v1);
        }

        this.mValueCallback = valueCallback;
        Intent v0 = new Intent("android.media.action.IMAGE_CAPTURE");
        if (v0.resolveActivity(this.getContext().getPackageManager()) != null) {
            try {
                v3 = File.createTempFile("JPEG_" + new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()) + '_', ".jpg", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES));
                v0.putExtra("PhotoPath", this.C);
                if (v3 != null) {
                    this.C = "file:" + v3.getAbsolutePath();
                    v0.putExtra("output", Uri.fromFile(v3));
                } else {
                    v0 = ((Intent) v1);
                }
            } catch (IOException v2) {
                Log.e(HomePageFragment.TAG, "Unable to create Image File", ((Throwable) v2));
            }
        }

        Intent v2_1 = new Intent("android.intent.action.GET_CONTENT");
        v2_1.addCategory("android.intent.category.OPENABLE");
        v2_1.setType("*/*");
        Intent[] v0_1 = v0 != null ? new Intent[]{v0} : new Intent[0];
        Intent intent = new Intent("android.intent.action.CHOOSER");
        intent.putExtra("android.intent.extra.INTENT", ((Parcelable) v2_1));
        intent.putExtra("android.intent.extra.TITLE", "Image Chooser");
        intent.putExtra("android.intent.extra.INITIAL_INTENTS", ((Parcelable[]) v0_1));
        this.startActivityForResult(intent, 1);
    }

    public final void loadUrl(String url) {
        if (SpecialPageHelper.a(url)) {
            this.n();
            this.mBrowser.loadUrl(url);
        }
    }

    public final void loadUrl(String arg3, String arg4) {
        String v0 = arg3.trim();
        Browser v1 = this.mBrowser;
        if (v1 != null) {
            v1.c();
            this.mBrowser.loadUrl(SpecialPageHelper.a(v0, arg4));
            this.mBrowser.clearHistory();
        }
    }

    public final boolean a() {
        if (this.getCurrentFragment() != null && this.mVideoController != null) {
            this.mVideoController.syncPosition(false);
        }

        return false;
    }

    public final void b(float arg4) {
        if (this.a != null) {
            this.a.b(arg4);
        }

        if (this.mTabInspector == null) {
            this.mTabInspector = TabInspector.getInstance();
        }

        if (this.mTabInspector != null) {
            if (!this.x()) {
                this.mTabInspector.mBrowserPage.setForwardRefreshFeed(true);
                ((ArticleMainActivity) this.getActivity()).showRedPoint();
            } else {
                this.mTabInspector.mBrowserPage.setForwardRefreshFeed(false);
                ((ArticleMainActivity) this.getActivity()).hideRedPoint();
            }

            BrowserPage v0 = this.mTabInspector.mBrowserPage;
            if (v0 == null) {
                return;
            }

            v0.onPageChangedEnd(false);
        }
    }

    public final void b(String arg2) {
        this.y();
        if (this.a != null) {
            this.a.mEtSearchInput.setText(((CharSequence) arg2));
        }
    }

    public final void setCanGoForward(boolean canGoForward) {
        if (this.mTabInspector != null) {
            this.mTabInspector.mBrowserPage.setForwardButtonEnabled(canGoForward);
        }
    }

    public final void setCanGoBack(boolean canGoBack) {
        if (this.mTabInspector != null) {
            this.mTabInspector.mBrowserPage.setBackButtonEnabled(canGoBack);
        }
    }

    public final Browser d() {
        return this.mBrowser;
    }

    public final void onMenuTabClick(boolean arg4) {
        super.d(arg4);
        if (this.a != null) {
            this.a.a(false);
        }

        if (this.mBrowser != null) {
            this.mBrowser.c();
            this.mBrowser.setWebViewVisibility(8);
        }

        UIUtils.setVisibility(this.mBrowserGuideView, 0);
        BrowserPage v0 = this.E();
        if (v0 != null) {
            v0.onPageChangedEnd(false);
        }
    }

    public final void e() {
        if (this.mBrowser != null) {
            this.mBrowser.unregisterReceiver();
        }
    }

    public final void f() {
        if (this.mBrowser != null) {
            this.mBrowser.pauseJSTimers();
        }
    }

    public final void g() {
        if (this.mBrowser != null) {
            this.mBrowser.resumeJSTimers();
        }
    }

    public final void h() {
        if (this.mBrowser != null) {
            this.mBrowser.onResume();
        }
    }

    public final void handleMsg(Message message) {
        super.handleMsg(message);
        switch (message.what) {
            case 10: {
                if ((message.obj instanceof WeatherBean)) {
                    Object v0 = message.obj;
                    if (v0 != null && this.getActivity() != null) {
                        this.V = (TextView) this.findViewById(com.ss.android.article.browser.R.id.tv_weather_temperature);
                        this.W = (TextView) this.findViewById(com.ss.android.article.browser.R.id.tv_weather_city);
                        this.X = (TextView) this.findViewById(com.ss.android.article.browser.R.id.tv_weather_status);
                        this.Y = (TextView) this.findViewById(com.ss.android.article.browser.R.id.tv_air_quality);
                        this.Z = (TextView) this.findViewById(com.ss.android.article.browser.R.id.tv_weather_pm2_5);
                        this.V.setText(String.format("%s°", Integer.valueOf(((WeatherBean) v0).current_temperature)));
                        this.W.setText(((WeatherBean) v0).city_name);
                        this.X.setText(((WeatherBean) v0).current_condition);
                        if (TextUtils.isEmpty(((WeatherBean) v0).quality_level)) {
                            ((WeatherBean) v0).quality_level = "优";
                        }

                        this.Y.setText(((WeatherBean) v0).quality_level);
                        this.Z.setText("PM2.5: " + ((WeatherBean) v0).aqi);
                    }
                }

                break;
            }
        }
    }

    public final int i() {
        int v0_1;
        if (this.mBrowser != null) {
            Browser v0 = this.mBrowser;
            v0_1 = v0.mSSWebView != null ? v0.mSSWebView.getProgress() : 100;
        } else {
            v0_1 = 0;
        }

        return v0_1;
    }

    public final boolean j() {
        boolean v0 = true;
        if (!this.o() && !this.D()) {
            v0 = false;
        }

        return v0;
    }

    public final boolean k() {
        boolean v0 = false;
        if (!android.support.design.a.isTextEmpty(this.getUrl())) {
            if (!this.mBrowser.isWebViewVisible()) {
                v0 = true;
            } else if (this.mBrowser != null && (this.mBrowser.canGoForward())) {
                v0 = true;
            }
        }

        return v0;
    }

    public final String getUrl() {
        String v0 = this.mBrowser == null || !this.mBrowser.isWebViewVisible() ? null : this.mBrowser.getUrl();
        return v0;
    }

    public final boolean m() {
        boolean v0;
        Browser v3 = this.mBrowser;
        if (v3 == null) {
            v0 = false;
        } else {
            if (this.a != null && (this.a.b())) {
                this.a.a(false);
                UIUtils.setVisibility(this.mBrowserGuideView, 0);
                this.checkCategoryTip();
                ((ArticleMainActivity) this.getActivity()).backWebsiteNavigationControl();
                return true;
            }

            if (!v3.isWebViewVisible()) {
                if (this.D()) {
                    this.c();
                    ((ArticleMainActivity) this.getActivity()).setRedCount(0);
                    ((ArticleMainActivity) this.getActivity()).hideRedPoint();
                    if (android.support.design.a.n()) {
                        ((ArticleMainActivity) this.getActivity()).finish();
                    } else {
                        UIUtils.a(this.getContext(), "再按一次退出");
                    }

                    return true;
                }

                return false;
            }

            if (this.E == null && this.mCustomViewCallback == null) {
                if (v3.canGoBack()) {
                    v3.goBack();
                    v0 = true;
                } else if (((ArticleMainActivity) this.getActivity()).backWebsiteNavigationControl()) {
                    if ((((ArticleMainActivity) this.getActivity()).isWebsiteUnbind()) && (v3.isWebViewVisible())) {
                        this.onMenuTabClick(false);
                    }

                    v0 = true;
                } else {
                    this.onMenuTabClick(false);
                    v0 = true;
                }

                return v0;
            }

            this.onHideCustomView();
            v0 = true;
        }

        return v0;
    }

    public final void n() {
        if (this.a != null) {
            this.a.a(false);
        }

        try {
            IVideoController v0_1 = this.mVideoController;
            if (v0_1 == null) {
//                goto label_9;
            } else {
                v0_1.dismiss(true);
            }
        } catch (Exception v0) {
        }

        label_9:
        this.mBrowser.setWebViewVisibility(0);
    }

    public final boolean o() {
        boolean v0 = this.mBrowser == null || !this.mBrowser.isWebViewVisible() ? false : true;
        return v0;
    }

    public final void onActivityResult(int arg6, int arg7, Intent arg8) {
        Uri[] v0;
        ValueCallback v1 = null;
        if (HomePageFragment.SDK_INT >= 21 || arg6 != 1) {
            if (arg6 == 1 && this.mValueCallback != null) {
                if (arg7 != -1) {
                    v0 = null;
                } else if (arg8 != null) {
                    String v2 = arg8.getDataString();
                    if (v2 != null) {
                        v0 = new Uri[]{Uri.parse(v2)};
                    } else {
                        v0 = null;
                    }
                } else if (this.C != null) {
                    v0 = new Uri[]{Uri.parse(this.C)};
                } else {
                    v0 = null;
                }

                this.mValueCallback.onReceiveValue(v0);
                this.mValueCallback = v1;
                return;
            }

            super.onActivityResult(arg6, arg7, arg8);
        }
    }

    public final void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        com.ss.android.article.browser.b.a.a();
        if (bundle == null) {
            bundle = this.getArguments();
        }

        this.mPreferenceManager = PreferenceManager.getInstance();
        this.mTabInspector = TabInspector.getInstance();
        this.aa = false;
        if (bundle != null) {
            this.T = bundle.getString("bundle_url", null);
            this.aa = bundle.getBoolean("bundle_isIncognito", false);
        }

        com.ss.android.article.browser.d.getInstance();
    }

    public final void onDestroy() {
        super.onDestroy();
        if (this.mBrowser != null) {
            this.mBrowser.unregisterReceiver();
        }
    }

    public final void onResume() {
        super.onResume();
        if (this.a != null) {
            this.a.a();
        }
    }

    public final void onSaveInstanceState(Bundle bundle) {
        super.onSaveInstanceState(bundle);
        bundle.putString("bundle_url", this.T);
        bundle.putBoolean("bundle_isIncognito", this.aa);
    }

    public final boolean p() {
        boolean v0 = (this.o()) || (this.x()) ? false : true;
        return v0;
    }

    public final String q() {
        String v0 = this.mBrowser == null || !this.mBrowser.isWebViewVisible() ? this.getString(com.ss.android.article.browser.R.string.a1u) : this.mBrowser.a.title;
        return v0;
    }

    public final void onHideCustomView() {
        WebChromeClient.CustomViewCallback v3 = null;
        Browser v0 = this.mBrowser;
        if (this.E != null && this.mCustomViewCallback != null && v0 != null) {
            Log.d(HomePageFragment.TAG, "onHideCustomView");
            v0.setWebViewVisibility(0);
            try {
                this.E.setKeepScreenOn(false);
            } catch (SecurityException v0_1) {
                Log.e(HomePageFragment.TAG, "WebView is not allowed to keep the screen on");
            }

            this.a(this.mPreferenceManager.mSharedPreferences.getBoolean("hidestatus", false), false);
            if (this.G != null) {
                ViewParent v0_2 = this.G.getParent();
                if (v0_2 != null) {
                    ((ViewGroup) v0_2).removeView(this.G);
                }

                this.G.removeAllViews();
            }

            this.G = ((FrameLayout) v3);
            this.E = ((View) v3);
            if (this.mVideoView != null) {
                Log.d(HomePageFragment.TAG, "VideoView is being stopped");
                this.mVideoView.stopPlayback();
                this.mVideoView.setOnErrorListener(((MediaPlayer.OnErrorListener) v3));
                this.mVideoView.setOnCompletionListener(((MediaPlayer.OnCompletionListener) v3));
                this.mVideoView = ((VideoView) v3);
            }

            if (this.mCustomViewCallback != null) {
                try {
                    this.mCustomViewCallback.onCustomViewHidden();
                } catch (Exception v0_3) {
                    Log.e(HomePageFragment.TAG, "Error hiding custom view", ((Throwable) v0_3));
                }
            }

            this.mCustomViewCallback = v3;
            ((ArticleMainActivity) this.getActivity()).setRequestedOrientation(this.mRequestedOrientation);
            return;
        }

        if (this.mCustomViewCallback != null) {
            try {
                this.mCustomViewCallback.onCustomViewHidden();
            } catch (Exception v0_3) {
                Log.e(HomePageFragment.TAG, "Error hiding custom view", ((Throwable) v0_3));
            }

            this.mCustomViewCallback = v3;
        }
    }

    public final void onGoBackClick() {
        this.m();
    }

    public final void onGoNextClick() {
        Browser v0 = this.mBrowser;
        if (v0 != null) {
            if (!v0.isWebViewVisible() && !android.support.design.a.isTextEmpty(v0.getUrl())) {
                this.n();
                BrowserPage v0_1 = this.E();
                if (v0_1 != null) {
                    v0_1.onPageChangedEnd(true);
                } else {
                }

                return;
            }

            if (!v0.canGoForward()) {
                return;
            }

            v0.goForward();
        }
    }

    public final void onPageStarted() {
        UIUtils.setVisibility(this.mBrowserPageRefreshIv, 0);
        if (this.mBrowserPageRefreshIv != null) {
            this.mBrowserPageRefreshIv.setImageResource(com.ss.android.article.browser.R.drawable.rb);
        }

        BrowserPage v0 = this.E();
        if (v0 != null) {
            v0.onPageChangedStart(true);
        }
    }

    public final void onPageFinished() {
        UIUtils.setVisibility(this.mBrowserPageRefreshIv, 0);
        if (this.mBrowserPageRefreshIv != null) {
            this.mBrowserPageRefreshIv.setImageResource(com.ss.android.article.browser.R.drawable.icon_tab_button_refresh);
        }

        BrowserPage v0 = this.E();
        if (v0 != null) {
            v0.onPageChangedEnd(true);
        }
    }

    protected final void w() {
        super.w();
        this.mLLSearchRoot = (LinearLayout) this.findViewById(com.ss.android.article.browser.R.id.ll_search_root);
        this.mCategoryNaviGrid = (LinearLayout) this.findViewById(com.ss.android.article.browser.R.id.category_navi_grid);
        this.mWebsiteNavigationGrid = (LinearLayout) this.findViewById(com.ss.android.article.browser.R.id.website_navi_grid);
        this.a = new ba(this.getContext(), this.mLLSearchRoot, this);
        this.a.c = this;
        this.mHomePageFakeSearchLayout.setOnClickListener(new View.OnClickListener() {
            public final void onClick(View v) {
                HomePageFragment.this.y();
            }
        });
        this.M = this.findViewById(com.ss.android.article.browser.R.id.ll_weather_container);
        if (ImmersedStatusBarHelper.isEnabled()) {
            this.M.setPadding(0, ImmersedStatusBarHelper.getStatusBarHeight(this.getContext(), true) + 20, 0, 0);
        }

        ((ArticleMainActivity) this.getActivity()).getPresenter().a(this.mHandler);
        View itemCategoryNavi = LayoutInflater.from(this.getContext()).inflate(com.ss.android.article.browser.R.layout.item_category_navi, this.mCategoryNaviGrid, false);
        View v1 = itemCategoryNavi.findViewById(com.ss.android.article.browser.R.id.tv_screen_name);
        ((TextView) v1).setText("火车票");
        int v9 = -1;
        ((TextView) v1).setTextColor(v9);
        ((ImageView) itemCategoryNavi.findViewById(com.ss.android.article.browser.R.id.screen_icon)).setImageResource(com.ss.android.article.browser.R.drawable.rh);
        ((ImageView) itemCategoryNavi.findViewById(com.ss.android.article.browser.R.id.xk)).setImageResource(com.ss.android.article.browser.R.drawable.r9);
        itemCategoryNavi.setOnClickListener(new View.OnClickListener() {
            public final void onClick(View view) {
                HomePageFragment.this.n();
                if (mBrowser != null) {
                    mBrowser.loadUrl("http://touch.train.qunar.com?bd_source=toutiao");
                }
                new com.ss.android.g.a.a$a("click_quick_category").a("category_name", "ticket").a().a();
            }
        });
        this.mCategoryNaviGrid.addView(itemCategoryNavi);
        Iterator<CategoryNaviItem> categoryNaviItemIterator = Constants.sCategoryNaviItemList.iterator();
        while (categoryNaviItemIterator.hasNext()) {
            CategoryNaviItem categoryNaviItem = categoryNaviItemIterator.next();
            LinearLayout itemNavi = (LinearLayout) LayoutInflater.from(this.getContext()).inflate(com.ss.android.article.browser.R.layout.item_navi, this.mCategoryNaviGrid, false);
            v1 = itemNavi.findViewById(com.ss.android.article.browser.R.id.tv_screen_name);
            ((TextView) v1).setText(((NaviItem) categoryNaviItem).mLabelResId);
            ((TextView) v1).setTextColor(v9);
            ((ImageView) itemNavi.findViewById(com.ss.android.article.browser.R.id.screen_icon)).setImageResource(((NaviItem) categoryNaviItem).mIconResId);
            itemNavi.setTag(categoryNaviItem);
            itemNavi.setOnClickListener(this.QuickCategoryClickListener);
            this.mCategoryNaviGrid.addView(itemNavi);
        }

        for (int i = 0; i < 6; ++i) {
            this.mWebsiteNavigationGrid.addView(
                    LayoutInflater.from(this.getContext()).inflate(com.ss.android.article.browser.R.layout.item_navi, this.mWebsiteNavigationGrid, false));
        }

        itemCategoryNavi = this.mWebsiteNavigationGrid.getChildAt(5);
        ((TextView) itemCategoryNavi.findViewById(com.ss.android.article.browser.R.id.tv_screen_name)).setText("更多");
        ((ImageView) itemCategoryNavi.findViewById(com.ss.android.article.browser.R.id.screen_icon)).setImageResource(com.ss.android.article.browser.R.drawable.icon_website_navi_more);
        final BrowserPresenter browserPresenter = ((ArticleMainActivity) this.getActivity()).getPresenter();
        String websiteListJson = BrowserSharedPreferencesWrapper.getString("website_list", null);
        List<NavigationBean> navigationBeanList;
        if (!TextUtils.isEmpty(websiteListJson)) {
            browserPresenter.mNavigationBeanList = new com.google.gson.Gson().fromJson(websiteListJson, new TypeToken<List<NavigationBean>>() {
            }.getType());
            navigationBeanList = browserPresenter.mNavigationBeanList.subList(0, 5);
        } else {
            if (TextUtils.isEmpty(BrowserSharedPreferencesWrapper.getString("website_list", null))) {
                android.support.design.a.createBrowserISApi().getNavigationBar("").enqueue(new NavigationCallback() {

                    public final void a(BaseNetBean baseNetBean) {
                        if (((WebsiteBean) baseNetBean).navigation != null
                                && !((WebsiteBean) baseNetBean).navigation.isEmpty()) {
                            browserPresenter.mNavigationBeanList = ((WebsiteBean) baseNetBean).navigation;
                            BrowserSharedPreferencesWrapper.putString("website_list", new Gson().toJson(browserPresenter.mNavigationBeanList));
                            if (HomePageFragment.this.a != null && !((ArticleMainActivity) browserPresenter.mBrowserPage).isFinishing()) {
                                ((ArticleMainActivity) browserPresenter.mBrowserPage).setWebsiteLayout(browserPresenter.mNavigationBeanList);
                            }
                        }
                    }

                    public final void b(Throwable throwable) {
                        android.support.design.a.d(throwable.getMessage());
                    }
                });
            }
            navigationBeanList = null;
        }

        if (navigationBeanList == null || (navigationBeanList.isEmpty())) {
            this.bindWebsiteNavigationGrid(android.support.design.a.getWebsiteNavigationBeanList());
        } else {
            this.bindWebsiteNavigationGrid(navigationBeanList);
        }

        BrowserBehavior.setOnScrollEventListener(this);
        BrowserBehavior.setViewChangeCallback(this);
        this.mBrowser = new Browser(((ArticleMainActivity) this.getActivity()), this, this.aa);
        this.mWebViewContainer = (ViewGroup) this.findViewById(com.ss.android.article.browser.R.id.browser_container);
        this.mBrowserPageFakeInputTv = (TextView) this.findViewById(com.ss.android.article.browser.R.id.browser_page_fake_input_tv);
        this.mBrowserPageRefreshIv = (ImageView) this.findViewById(com.ss.android.article.browser.R.id.browser_page_refresh_iv);
        this.mBrowserPageHeader = (LinearLayout) this.findViewById(com.ss.android.article.browser.R.id.browser_page_header);
        this.mBrowserProgressBar = (BrowserProgressBar) this.findViewById(com.ss.android.article.browser.R.id.browser_page_loading_progress);
        final WebView webView = this.mBrowser.getWebView();
        if (webView != null) {
            ViewParent parent = ((View) webView).getParent();
            if ((parent instanceof ViewGroup)) {
                ((ViewGroup) parent).removeView(webView);
            }
        }

        if (this.mWebViewContainer != null) {
            this.mWebViewContainer.addView(webView, 0);
        }

        if (this.mBrowserPageHeader != null) {
            this.mBrowserPageHeader.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {

                public final boolean onPreDraw() {
                    if (mBrowserPageHeader.getBottom() <= 0) {
                        return true;
                    } else {
                        mBrowserPageHeader.getViewTreeObserver().removeOnPreDrawListener(this);
                        if (webView != null) {
                            ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) webView.getLayoutParams();
                            layoutParams.topMargin = mBrowserPageHeader.getBottom();
                            webView.setLayoutParams(layoutParams);
                        }
                        return false;
                    }
                }
            });
        }

        this.mBrowser.a(this.mBrowserPageFakeInputTv);
        if (this.mBrowserPageFakeInputTv != null) {
            this.mBrowserPageFakeInputTv.setOnClickListener(new View.OnClickListener() {

                public final void onClick(View view) {
                    HomePageFragment.this.y();
                    if (HomePageFragment.this.a != null) {
                        HomePageFragment.this.a.a(mBrowser.getUrl(), mBrowser.a.title);
                    }
                }
            });
        }

        if (this.mBrowserPageRefreshIv != null) {
            this.mBrowserPageRefreshIv.setOnClickListener(this.mRefreshOnClickListener);
        }

        if (!TextUtils.isEmpty(this.T)) {
            this.n();
            this.mBrowser.loadUrl(this.T);
        }
    }

    public final boolean x() {
        boolean v0 = this.mFeedAreaContainer == null || Math.abs(((BaseHomePageFragment) this).w) >= this.mNavigationGridHeight ? false : true;
        return v0;
    }

    public final void y() {
        super.y();
        if (this.a != null) {
            this.a.a(true);
        }

        try {
            IVideoController v0_1 = this.mVideoController;
            if (v0_1 == null) {
//                goto label_10;
            } else {
                v0_1.dismiss(true);
            }
        } catch (Exception v0) {
        }

//        label_10:
        UIUtils.setVisibility(this.mBrowserGuideView, 8);
    }

    final static class w$a implements MediaPlayer.OnCompletionListener, MediaPlayer.OnErrorListener {
        private final HomePageFragment a;

        w$a(HomePageFragment arg1, byte arg2) {
            this(arg1);
        }

        private w$a(HomePageFragment arg1) {
            this.a = arg1;

        }

        public final void onCompletion(MediaPlayer arg2) {
            this.a.onHideCustomView();
        }

        public final boolean onError(MediaPlayer arg2, int arg3, int arg4) {
            return false;
        }
    }
}

